﻿var Ctrls = function () {
    // Metodos publicos y Propiedades
    return {
        getValue: function (obj) {
            return obj.value;
        },
        GetValueCombo: function (name_combo) {
            var cmb = $get(name_combo);
            var value = null;
            if (cmb != null) {
                var comboHidden = name_combo + '_ddlControl1_HiddenField';
                if ($get(comboHidden) != null) {
                    var index = $get(comboHidden).value;
                    if (index > -1) {
                        if (cmb.control == undefined) {
                            value = cmb.getElementsByTagName('li')[index].getAttribute('_value');
                        }
                        else {
                            if (cmb.control._optionListControl.childNodes.length > 0) {
                                value = cmb.control._optionListControl.childNodes[index].getAttribute('_value')
                            }
                        }
                    }
                }
            }
            return value;
        },
        Valid: function (form) {
            var objectsValid = [];
            var count = 0;
            var expression = "";
            f = document.getElementById(form);
            for (i = 0; i < f.elements.length; i++) {
                if (f.elements[i].onchange != null) {
                    if (f.elements[i].onchange.toString().indexOf("ValidObject") >= 0) {
                        if (f.elements[i].nodeName == "SELECT") {
                            objectsValid[count] = ValidObjectCmb(f.elements[i]);
                            count++;
                        }
                        else {
                            objectsValid[count] = ValidObject(f.elements[i]);
                            count++;
                            if (f.elements[i].onchange.toString().indexOf("ValidExpression(") >= 0) {
                                expression = "";
                                for (j = 0; j < f.elements[i].attributes.length; j++) {
                                    if (f.elements[i].attributes[j].name = "ValidationExpression") {
                                        expression = f.elements[i].attributes[j].value;
                                    }
                                }
                                if (expression != "") {
                                    objectsValid[count] = ValidExpression(f.elements[i], expression);
                                    count++;
                                }
                            }
                        }
                    }
                }
            }
            if (objectsValid.indexOf(false) > -1) {
                return false;
            }
            return true;
        }
    }
} ();